﻿using DocumentFormat.OpenXml.Drawing;
using MaterialDesignThemes.Wpf.Transitions;
using MaterialDesignThemes.Wpf;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Documents;
using System;
using System.Configuration;
using System.Linq;
using System.Windows.Data;
using FullApp1.Core;

namespace FullApp1.ViewModels
{
    // MainWindowViewModel.cs
    public class MainWindowViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;


        private readonly ICollectionView _demoItemsView;
        private DemoItem? _selectedItem;
        private int _selectedIndex;
        private string? _searchKeyword;
        private bool _controlsEnabled = true;

        public MainWindowViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            // 初始导航到主视图
            //_regionManager.RequestNavigate("ContentRegion", "ExistingPageView");
            _regionManager.RequestNavigate("ContentRegion", "LicenseDetailView");




            DemoItems = new ObservableCollection<DemoItem>(new[]
        {
            new DemoItem(
                "Home",
                typeof(Home)                
            )
            {
                HorizontalScrollBarVisibilityRequirement = ScrollBarVisibility.Disabled
            }
        });

            
            


            HomeCommand = new AnotherCommandImplementation(
                _ =>
                {
                    SearchKeyword = string.Empty;
                    SelectedIndex = 0;
                });

            MovePrevCommand = new AnotherCommandImplementation(
                _ =>
                {
                    if (!string.IsNullOrWhiteSpace(SearchKeyword))
                        SearchKeyword = string.Empty;

                    SelectedIndex--;
                },
                _ => SelectedIndex > 0);

            MoveNextCommand = new AnotherCommandImplementation(
               _ =>
               {
                   if (!string.IsNullOrWhiteSpace(SearchKeyword))
                       SearchKeyword = string.Empty;

                   SelectedIndex++;
               },
               _ => SelectedIndex < DemoItems.Count - 1);
        }

        

        public string? SearchKeyword
        {
            get => _searchKeyword;
            set
            {
                if (SetProperty(ref _searchKeyword, value))
                {
                    _demoItemsView.Refresh();
                }
            }
        }

        public ObservableCollection<DemoItem> DemoItems { get; }

        public DemoItem? SelectedItem
        {
            get => _selectedItem;
            set => SetProperty(ref _selectedItem, value);
        }

        public int SelectedIndex
        {
            get => _selectedIndex;
            set => SetProperty(ref _selectedIndex, value);
        }

        public bool ControlsEnabled
        {
            get => _controlsEnabled;
            set => SetProperty(ref _controlsEnabled, value);
        }

        public AnotherCommandImplementation HomeCommand { get; }
        public AnotherCommandImplementation MovePrevCommand { get; }
        public AnotherCommandImplementation MoveNextCommand { get; }


    }
}

